#ifndef __AS_IMAGE__H__
#define __AS_IMAGE__H__

#include "ASControl.h"
#include "..\base\ASGraphic.h"

#define AS_IMAGE_PATH_LEN 128

typedef enum
{
    AS_IMAGE_FROM_RES,
    AS_IMAGE_FROM_FILE,
    AS_IMAGE_FROM_BUFFER,//just read data from existed canvas

    AS_IAMGE_SRC_TYPE_MAX
} as_image_src_type;

typedef enum
{
    /*display start position*/
    AS_IMAGE_LEFT_TOP = 0x000001,
    AS_IMAGE_CENTER =   0x000002,
    AS_IMAGE_CUSTOM =   0x000004,

    /*display type*/
    AS_IMAGE_NORMAL =   0x10000,
    AS_IMAGE_TILED =    0x20000,

    AS_IMAGE_SHOW_TYPE_MAX
} as_image_show_type;


typedef struct
{
    /* base */
    as_control base;

    /* attributes */
    as_res_info res_info;
    //ASINT canvas_hdlr;
    //ASUINT8* canvas_buf;
    //ASINT canvas_frames;//frame counts
    //ASINT canvas_cur_frame_idx;//which frame you want to show
    as_image_src_type src_type;
    ASINT if_trans;
    ASWCHAR path[AS_IMAGE_PATH_LEN];
#ifndef AS_USE_IMAGE_RESOURCE_MANAGER
    ASCHAR ascii_path[AS_IMAGE_PATH_LEN];
#endif
    as_rect region;//exactly region of the image you want to show
    ASINT alpha;//value range [0,255], 0 means completely transparent
    ASUINT16 img_w, img_h;
    as_image_show_type show_type;
    ASINT16 x_off, y_off; //for AS_IMAGE_CUSTOM

    /* methods */
    /*
     *	[description] load the image data
     *  [param] ctrl_p : which you want to take action on
     *  [param] if_auto_resize : TRUE or FALSE
     *  [return] as_ret : AS_OK ,or error code
     */
    as_ret (*load_data)(as_control* ctrl_p, ASINT if_auto_resize);

    /*
     *	[description] unload the image data
     *  [param] ctrl_p : which you want to take action on
     *  [return] as_ret : AS_OK ,or error code
     */
    as_ret (*unload_data)(as_control* ctrl_p);

    /*
     *	[description] set the region of the image, and you can show part of it.
     *  [param] ctrl_p : which you want to take action on
     *  [param] region : rectangle region of the image
     *  [return] as_ret : AS_OK ,or error code
     */
    as_ret (*set_region)(as_control* ctrl_p, as_rect region);

    /*
     *	[description] set the transparent value of the image.
     *  [param] ctrl_p : which you want to take action on
     *  [param] alpha : value range [0,255], 0 means completely transparent
     *  [return] as_ret : AS_OK ,or error code
     */
    as_ret (*set_alpha)(as_control* ctrl_p, ASINT alpha);

    /*
     *	[description] set which frame of the image you want to show (just for multi-frame gif).
     *  [param] ctrl_p : which you want to take action on
     *  [param] idx : value range [0,canvas_frames]
     *  [return] as_ret : AS_OK ,or error code
     */
    as_ret (*set_frame_idx)(as_control* ctrl_p, ASINT idx);

    /*
     *	[description] select one from as_image_show_type for image show.
     *  [param] ctrl_p : which you want to take action on
     *  [param] show_type : enum as_image_show_type
     *  [return] as_ret : AS_OK ,or error code
     */
    as_ret (*set_show_type)(as_control* ctrl_p, as_image_show_type show_type);

    /*
     *	[description] set image show offset from its area,it is valid just in case of AS_IMAGE_CUSTOM.
     *  [param] ctrl_p : which you want to take action on
     *  [param] x_off : offset to area.x
     *  [param] y_off : offset to area.y
     *  [return] as_ret : AS_OK ,or error code
     */
    as_ret (*set_show_offset)(as_control* ctrl_p, ASINT x_off, ASINT y_off);

    as_ret (*set_if_trans)(as_control* ctrl_p, ASINT if_trans);

    /**/
    as_ret (*reload)(as_control* ctrl_p, ASWSTR path, as_image_src_type type, ASINT if_auto_resize);
} as_image;

/*
 *	[description] create a image control
 *  [param] paint_buf : which buffer do yo want to paint this control
 *  [param] area : control area
 *  [param] type : image source type (enum as_image_src_type)
 *  [param] path : image source path (in ucs2)
 *  [param] if_auto_resize : if this image need auto-resize to fit area
 *  [return] as_image* : if success return the pointer,else return NULL.
 */
as_image* as_ctrl_image_create(as_rect area,
                               as_image_src_type type, ASWSTR path, ASINT if_auto_resize);

/*
 *	[description] destory a image control
 *  [param] ctrl_image_p : which image do you want to destory
 *  [return] as_ret : if success return AS_OK , else return error codes.
 */
as_ret as_ctrl_image_destroy(as_image* ctrl_image_p);
#endif//__AS_IMAGE__H__